<template>
	<div>
		<!--<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:sysUserExperience:add']">新增</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['system:sysUserExperience:edit']">修改</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['system:sysUserExperience:remove']">删除</el-button>
			</el-col>
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['system:sysUserExperience:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>-->
		<el-row style="padding: 10px;">
			<el-col :span="24">
				<el-timeline :reverse="false">
					<el-timeline-item v-for="(activity, index) in sysUserExperienceList" :key="index" :timestamp="activity.startDate">
						<div>
							<el-col :span="20">
								{{activity.company}}-{{activity.post}}
							</el-col>
							<el-col v-if="btn" :span="4">
								<el-button type="success" size="mini" @click="handleUpdate(activity)">修改</el-button>
								<el-button type="danger" size="mini" @click="handleDelete(activity)">删除</el-button>
							</el-col>
						</div>
						<div>
							{{activity.content}}
						</div>
					</el-timeline-item>
				</el-timeline>
			</el-col>
		</el-row>
		<el-row>
			<div v-if="btn" style="margin-left: 30px;padding-bottom: 10px;">
				<el-button type="primary" size="mini" @click="handleAdd">新增</el-button>
			</div>
		</el-row>

		<!-- 添加或修改用户经历对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<el-form-item label="单位" prop="company">
					<el-input v-model="form.company" placeholder="请输入单位" />
				</el-form-item>
				<el-form-item label="内容">
					<el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="form.content">
					</el-input>
					<!--<editor v-model="form.content" :min-height="192" />-->
				</el-form-item>
				<el-form-item label="岗位" prop="post">
					<el-input v-model="form.post" placeholder="请输入岗位" />
				</el-form-item>
				<el-form-item label="开始时间" prop="startDate">
					<el-date-picker clearable size="small" v-model="form.startDate" type="date" value-format="yyyy-MM-dd" placeholder="选择开始时间">
					</el-date-picker>
				</el-form-item>
				<el-form-item label="结束时间" prop="endDate">
					<el-date-picker clearable size="small" v-model="form.endDate" type="date" value-format="yyyy-MM-dd" placeholder="选择结束时间">
					</el-date-picker>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import { listSysUserExperience, getSysUserExperience, delSysUserExperience, addSysUserExperience, updateSysUserExperience } from "@/api/system/userExperience";
	import Editor from '@/components/Editor';

	export default {
		name: "SysUserExperience",
		components: {
			Editor,
		},
		props: {
			userModel: {
				type: Object
			},
			btn: {
				type: Boolean
			}
		},
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 用户经历表格数据
				sysUserExperienceList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					userId: null,
					company: null,
					content: null,
					post: null,
					startDate: null,
					endDate: null
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {}
			};
		},
		created() {
			this.queryParams.userId = this.userModel.userId
			this.getList();
		},
		methods: {
			/** 查询用户经历列表 */
			getList() {
				this.loading = true;
				listSysUserExperience(this.queryParams).then(response => {
					this.sysUserExperienceList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					id: null,
					delFlag: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					userId: null,
					company: null,
					content: null,
					post: null,
					startDate: null,
					endDate: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.id)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 新增按钮操作 */
			handleAdd() {
				this.reset();
				this.form.userId = this.userModel.userId
				this.open = true;
				this.title = "添加用户经历";
			},
			/** 修改按钮操作 */
			handleUpdate(row) {
				this.reset();
				const id = row.id || this.ids
				getSysUserExperience(id).then(response => {
					this.form = response.data;
					this.open = true;
					this.title = "修改用户经历";
				});
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs["form"].validate(valid => {
					if(valid) {
						if(this.form.id != null) {
							updateSysUserExperience(this.form).then(response => {
								this.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addSysUserExperience(this.form).then(response => {
								this.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
			/** 删除按钮操作 */
			handleDelete(row) {
				const ids = row.id || this.ids;
				this.$confirm('是否确认删除用户经历编号为"' + ids + '"的数据项?', "警告", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning"
				}).then(function() {
					return delSysUserExperience(ids);
				}).then(() => {
					this.getList();
					this.msgSuccess("删除成功");
				})
			},
			/** 导出按钮操作 */
			handleExport() {
				this.download('system/userExperience/export', {
					...this.queryParams
				}, `system_sysUserExperience.xlsx`)
			}
		}
	};
</script>